package com.tyao.note.controller;

import javax.servlet.http.HttpSession;

import com.tyao.note.model.TSUser;

/**
 * Controller类共有的属性和方法
 * @author Ty-user1
 *
 */
public class BaseController {
	/**
	 * 从session中获取用户对象
	 * @param session
	 * @return 返回用户ID
	 */
	public int getId(HttpSession session) {
		TSUser user = (TSUser) session.getAttribute("user");
		if (user!=null) {
			return user.getId();
		} else {
			throw new RuntimeException("用户ID不存在");
		}
	}
	public String getUserName(HttpSession session) {
		TSUser user = (TSUser) session.getAttribute("user");
		if (user!=null) {
			return user.getUsername();
		} else {
			throw new RuntimeException("用户名不存在");
		}
	}
}
